<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img id="light" src="../img/off.gif">
<script>
    var light = document.getElementById("light");
    var flag = false;
    light.onclick = function () {
        if (flag) {
            light.src = "../img/off.gif";
            flag = false;
        } else {
            light.src = "../img/on.gif";
            flag = true;
        }
    }
</script>


</body>
</html>